package com.gem.netty.service.card;

import com.gem.entity.Card;
import com.gem.entity.Game;
import com.gem.enums.ClientMessageType;
import com.gem.factory.card.CardBaseFactory;
import com.gem.factory.game.GameFactory;
import com.gem.netty.entity.CardInfo;
import com.gem.netty.entity.ClientContent;
import com.gem.netty.entity.CurrentUser;
import com.gem.pipeline.BusinessProcess;
import com.gem.pipeline.ProcessContext;
import com.gem.utils.R;

import java.util.List;

/**
 * Author: Xhy
 * CreateTime: 2022-09-25 14:07
 *  是否卡牌库还有牌
 */
public class IsExistCardService  implements BusinessProcess<ClientContent> {
    @Override
    public void process(ProcessContext<ClientContent> context) {
        Game game = GameFactory.get(context.getData().getRoomId());
        CardInfo cardInfo = context.getData().getContent().getCardInfo();
        int i = 0;
        boolean res = true;
        List<Card> cardList = game.getShowCards().get(cardInfo.getType());
        CurrentUser user = game.getUsers().get(game.getCurrentIndex());
        // 校验场上是否有该牌 || 用户自己压住的牌
        for (; i <cardList.size(); i++) {
            if (cardList.get(i).getNo() == cardInfo.getNo() || existTsCard(user.getTSCards(),cardInfo.getNo())){
                res = false;
                break;
            }
        }
        context.setNeedBreak(res);
    }

    private boolean existTsCard(List<CardInfo> tsCards, Integer no) {
        for (CardInfo tsCard : tsCards) {
            if (tsCard.getNo() == no){
                return true;
            }
        }
        return false;
    }
}
